/**
 * https://leetcode.cn/problems/maximum-average-subarray-i/
 */
function findMaxAverage(nums: number[], k: number): number {
  let maxSum = 0;
  for (let i = 0; i < nums.length; i < k) {
    maxSum += nums[i] 
  }
  let ans = maxSum
  for (let i = k; i < nums.length; i++) {
    // 删掉过期的 i - k 值，然后再加上自己
    maxSum = maxSum - nums[i - k] + nums[i]
    ans = Math.max(maxSum, ans)
  }

  return ans / k;
}
